<template>
  <div class="app-container">
    <div class="filter-container">
      <el-form :inline="true" :model="listQuery" class="demo-form-inline">
        <el-form-item prop="code" label="项目编号">
          <el-input v-model="listQuery.code" placeholder="项目编号" style="width: 200px;" />
        </el-form-item>
        <el-form-item prop="name" label="项目名称">
          <el-input v-model="listQuery.name" placeholder="项目名称" style="width: 200px;" />
        </el-form-item>
        <el-form-item>
          <el-button type="success" icon="Search" @click="handleFilter">
            查询
          </el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="app-container">
      <el-table v-loading="listLoading"
                :data="projectList"
                border
                fit
                highlight-current-row
                tooltip-effect="dark"
                style="width: 100%; margin-bottom: 20px;">
        <el-table-column align="center" type="index" label="序号" width="60px" />
        <el-table-column align="center" label="二级项目编码" prop="code" min-width="155px" sortable show-overflow-tooltip>
          <template v-slot="{row}">{{ row.code }}</template>
        </el-table-column>
        <el-table-column align="center" label="二级项目名称" prop="name" min-width="105px" sortable show-overflow-tooltip>
          <template v-slot="{row}">{{ row.name }}</template>
        </el-table-column>
        <el-table-column align="center" label="项目编号" prop="code" min-width="105px" sortable show-overflow-tooltip>
          <template v-slot="{row}">{{ row.code }}</template>
        </el-table-column>
        <el-table-column align="center" label="起始年度" prop="startTime" min-width="105px" sortable show-overflow-tooltip>
          <template v-slot="{row}">{{ row.startTime }}</template>
        </el-table-column>
        <el-table-column align="center" label="终止年度" prop="endTime" min-width="105px" sortable show-overflow-tooltip>
          <template v-slot="{row}">{{ row.endTime }}</template>
        </el-table-column>
        <el-table-column align="center" label="最后修改时间" width="180px" prop="updateTime" />
        <el-table-column label="操作" width="150" align="center" fixed="right">
          <template v-slot="{row}">
            <el-button text type="primary" @click="openProjectModel(row)">查看预算绩效</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination v-model:total="total" v-model:page="listQuery.pageNum" v-model:limit="listQuery.pageSize" @pagination="getList" class="pagination-model" />
    </div>
  </div>
</template>
<script setup>
import {ref, onMounted} from 'vue'
import {doGet} from "@/config/http"
import {svc} from "@/config/common"
import Pagination from "@/components/Pagination/index.vue";

const props = defineProps({
  radioNum: {
    required: false,
    type: String,
  }
})
const emit = defineEmits(['openProjectKpi'])

let projectList = ref([])
let listLoading = ref(true)
let total = ref(0)
let listQuery = ref({
  pageNum: 1,
  pageSize: 10,
  sortField: 'id',
  sortType: 'desc',
  projectTwoId: null,
  name: null,
  viability: null,
  source: null,
  attribute: null,
  totalFund: null,
  putinFund: null,
  currFund: null,
  useGovId: null,
  applyGovId: null,
  previousArrange: null,
  managerOrgId: null,
  managerName: null,
  managerUserContact: null,
  workGovId: null,
  workUserId: null,
  workUserContact: null,
  state: null,
  startTime: null,
  endTime: null,
  isDebenture: null,
  isScientific: null,
  isConstruction: null,
  constructionDesc: null,
  isAgent: null,
  agentGovId: null,
  isGovernmentPurchase: null,
  purchaseProject: null,
  purchaseKind: null,
  purchaseRequire: null,
  purchaseDateStart: null,
  purchaseDateEnd: null,
  purchaseAttr: null,
  purchaseFund: null,
  purchasePrice: null,
  purchaseNum: null,
  purchaseUnit: null,
  createTimeStart: null,
  createTimeEnd: null,
  updateTimeStart: null,
  updateTimeEnd: null,
})
let radioRow = null

console.log('ccccccccccccccccc')
// watch(() => props.itemsVisible, async val => {
//   if (val === '3') {
//     await getList()
//   }
// })

onMounted(async () => {
  await getList()
})

// 获取数据
async function getList() {
  listLoading.value = true
  let res = await doGet(svc, '/budget-two/page', listQuery.value)
  listLoading.value = false
  total.value = parseInt(res['total'])
  projectList.value = res['records']
  radioRow = null
}

// 查询
async function handleFilter() {
  listQuery.value['pageNum'] = 1
  await getList()
}

function openProjectModel(row) {
  emit('openProjectKpi', {id: row.id, type: 'budgetTwo'})
}
</script>
<style>
.pagination-model {
  right: 36px !important;
}
</style>
